#!/usr/bin/env python3
# fileencoding=utf-8

'''
解压 zip 文件，其中的文件名是 GB18030 编码，但系统是 Unicode 编码
'''

import sys
import os
from gbzip import ZipFile
from getpass import getpass

def main():
  try:
    z = ZipFile(sys.argv[1])
    while True:
      try:
        z.extractall()
      except RuntimeError: # encrypted zipfile
        passwd = getpass('Enter correct password: ').encode()
        z.setpassword(passwd)
      else:
        break
    print('Everything is ok.')
  except IndexError:
    sys.exit('give me exactly one zipfile to extract.')

if __name__ == '__main__':
  main()
